﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FonShare.Classes.Data;

namespace FonShare
{
    public partial class SignUp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void SignUpButton_Click(object sender, EventArgs e)
        {
            FS_DataClassesDataContext dc = new FS_DataClassesDataContext();
            if (dc.FS_Users.Where(record => record.Username == UsernameTextBox.Text).Count() == 0)
            {
                FS_User newUser = new FS_User();
                newUser.Username = UsernameTextBox.Text;
                newUser.Password = PasswordTextBox.Text;
                dc.FS_Users.InsertOnSubmit(newUser);
                dc.SubmitChanges();
                MessageLabel.Text = "User created, you can log in.";
            }
            else
            {
                MessageLabel.Text = "Unfortunately, this username already exists, please choose another one.";
            }
        }
    }
}
